import { createMessage } from "./messaging";
// const traverseNode = (node) => {
//   if (node.type === "Layer") {
//     // Do something with Layer
//     console.log(node, "Layer");
//   } else if (node.type === "Group") {
//     // Do something with Group
//     console.log(node, "Group");
//   } else if (node.type === "Psd") {
//     // Do something with Psd
//     console.log(node, "Psd");
//   } else {
//     throw new Error("Invalid node type");
//   }

//   node.children?.forEach((child) => traverseNode(child));
// };

const worker = new Worker(new URL("./psdworkers.js", import.meta.url), {
  type: "module",
});
worker.addEventListener("message", (e) => {
  console.log(e.data, "e.data");
});
export const parseHtml = async (buffer) => {
  // const url = URL.createObjectURL(file);
  const obj = createMessage("ParseData", buffer);
  console.log(obj, "---obj---");
  worker.postMessage(obj);
  //   PSD.fromURL(url).then((psd) => {
  //     console.log(psd);
  //   });
  //   const buffer = await file.arrayBuffer();
  //   //   const psdFile = Psd.parse(result);
  //   //   console.log(psdFile, '00000');
  //   //   traverseNode(psdFile);
  //   worker.postMessage(createMessage("ParseData", buffer), [buffer]);
};

export default {
  parseHtml,
};
